package com.atguigu.service.impl;

import com.atguigu.dao.BaseDao;
import com.atguigu.service.BaseService;
import com.atguigu.util.CastUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

public  abstract class BaseServiceImpl<T> implements BaseService<T> {

    //    @Autowired
//    public BaseDao<T> baseDao;
    public abstract BaseDao<T> getBaseDao();
    @Override
    public PageInfo<T> findPage(Map filters) {
        int pageNum = CastUtil.castInt(filters.get("pageNum"));
        int pageSize = CastUtil.castInt(filters.get("pageSize"));
        PageHelper.startPage(pageNum, pageSize);
        List<T> list = getBaseDao().findPage(filters);
        return new PageInfo<>(list,3);
    }

    @Override
    public void insert(T t) {
        getBaseDao().insert(t);
    }

    @Override
    public T getById(Serializable id) {

        return getBaseDao().getById(id);
    }

    @Override
    public void update(T t) {
        getBaseDao().update(t);
    }

    @Override
    public void delete(Serializable id) {
        getBaseDao().delete(id);
    }

}
